--[[
Description: 
Author: DingZY
email: 331646081@qq.com
Date: 2021-06-08 20:35:38
LastEditTime: 2021-06-10 16:58:37
--]]
Judge_menu = false
Judge_exit = false

Color = {
    red = {r = 255 / 255, g = 0 / 255, b = 0 / 255},
    blue = {r = 0 / 255, g = 0 / 255, b = 255 / 255},
    SpringGreen = {r = 0 / 255, g = 205 / 255, b = 102 / 255},
    Yellow = {r = 255 / 255, g = 255 / 255, b = 0},
    Chocolate = {r = 205 / 255, g = 102 / 255, b = 29 / 255},
    CadetBlue = {r = 152 / 255, g = 245 / 255, b = 255 / 255},
    Wheat = {r = 245 / 255, g = 222 / 255, b = 179 / 255},
    White = {r = 255 / 255, g = 255 / 255, b = 255 / 255}
}

function UseDefaultFont(text, x, y, size)
    love.graphics.setColor(155 / 255, 48 / 255, 255 / 255)
    love.graphics.setBlendMode("alpha")
    local font = love.graphics.newFont(size)
    love.graphics.setFont(font)
    love.graphics.print(text, x, y + size)
end

function Circle_Move()
    if love.keyboard.isDown("w") then
        Circle.y = Circle.y - 5
        if Circle.y - Circle.r < Rect.y then
            Circle.y = Rect.y + Circle.r
        end
    end
    if love.keyboard.isDown("s") then
        Circle.y = Circle.y + 5
        if Circle.y + Circle.r > Rect.y + Rect.h then
            Circle.y = Rect.y + Rect.h - Circle.r
        end
    end
    if love.keyboard.isDown("a") then
        Circle.x = Circle.x - 5
        if Circle.x - Circle.r < Rect.x then
            Circle.x = Rect.x + Circle.r
        end
    end
    if love.keyboard.isDown("d") then
        Circle.x = Circle.x + 5
        if Circle.x + Circle.r > Rect.x + Rect.w then
            Circle.x = Rect.x + Rect.w - Circle.r
        end
    end
end

function Draw_Border()
    love.graphics.setColor(Border_color.r, Border_color.g, Border_color.b)
    love.graphics.rectangle("fill", Border.x, Border.y, Border.w, Border.h)
end

function Draw_Rect()
    love.graphics.setColor(Rect_color.r, Rect_color.g, Rect_color.b)
    love.graphics.rectangle("fill", Rect.x, Rect.y, Rect.w, Rect.h)
end

function Draw_Main()
    love.graphics.setColor(Circle_color.r, Circle_color.g, Circle_color.b)
    love.graphics.circle("fill", Circle.x, Circle.y, Circle.r, Circle.s)
    love.graphics.setColor(Button_menu_color.r, Button_menu_color.g, Button_menu_color.b)
    love.graphics.rectangle("fill", Button_menu.x, Button_menu.y, Button_menu.w, Button_menu.h)
    love.graphics.setColor(Button_exit_color.r, Button_exit_color.g, Button_exit_color.b)
    love.graphics.rectangle("fill", Button_exit.x, Button_exit.y, Button_exit.w, Button_exit.h)
    love.graphics.setColor(Circle_color.r, Circle_color.g, Circle_color.b)
    UseDefaultFont("Menu", Button_menu.x + 15, Button_menu.y, 60)
    UseDefaultFont("Exit", Button_exit.x + 35, Button_exit.y, 60)
end

function Draw_Menu()
    love.graphics.setColor(Menu_color.r, Menu_color.g, Menu_color.b)
    love.graphics.rectangle("fill", Menu_rect.x, Menu_rect.y, Menu_rect.w, Menu_rect.h)
    UseDefaultFont("Change the color", Menu_rect.x + 20, Menu_rect.y, 30)
    love.graphics.setColor(Button_Red_color.r, Button_Red_color.g, Button_Red_color.b)
    love.graphics.rectangle("fill", Button_Red.x, Button_Red.y, Button_Red.w, Button_Red.h)
    UseDefaultFont("Red", Button_Red.x + 20, Button_Red.y - 22, 30)
    love.graphics.setColor(Button_Blue_color.r, Button_Blue_color.g, Button_Blue_color.b)
    love.graphics.rectangle("fill", Button_Blue.x, Button_Blue.y, Button_Blue.w, Button_Blue.h)
    UseDefaultFont("Blue", Button_Blue.x + 17, Button_Blue.y - 22, 30)
    love.graphics.setColor(Button_Close_color.r, Button_Close_color.g, Button_Close_color.b)
    love.graphics.rectangle("fill", Button_Close.x, Button_Close.y, Button_Close.w, Button_Close.h)
    UseDefaultFont("Close", Button_Close.x + 7, Button_Close.y - 22, 30)
end

function Draw_Exit()
    love.graphics.setColor(Exit_color.r, Exit_color.g, Exit_color.b)
    love.graphics.rectangle("fill", Exit_rect.x, Exit_rect.y, Exit_rect.w, Exit_rect.h)
    UseDefaultFont("Are you sure?", Exit_rect.x + 30, Exit_rect.y - 10, 30)
    love.graphics.setColor(Button_Cancel_color.r, Button_Cancel_color.g, Button_Cancel_color.b)
    love.graphics.rectangle("fill", Button_Cancel.x, Button_Cancel.y, Button_Cancel.w, Button_Cancel.h)
    UseDefaultFont("Cancel", Button_Cancel.x, Button_Cancel.y - 22, 30)
    love.graphics.setColor(Button_Sure_color.r, Button_Sure_color.g, Button_Sure_color.b)
    love.graphics.rectangle("fill", Button_Sure.x, Button_Sure.y, Button_Sure.w, Button_Sure.h)
    UseDefaultFont("Sure", Button_Sure.x + 10, Button_Sure.y - 22, 30)
end

function Main_Mouse_Move()
    local x = love.mouse.getX()
    local y = love.mouse.getY()
    if x >= 1200 and x <= 1400 and y >= 500 and y <= 700 then
        if love.mouse.isDown(1) then
            Button_exit_color = Button_pressed_color
            Judge_exit = true
        else
            Button_exit_color = Button_inside_color
        end
    else
        Button_exit_color = Button_outside_color
    end
    if x >= 1200 and x <= 1400 and y >= 100 and y <= 300 then
        if love.mouse.isDown(1) then
            Button_menu_color = Button_pressed_color
            Judge_menu = true
        else
            Button_menu_color = Button_inside_color
        end
    else
        Button_menu_color = Button_outside_color
    end
end

function Exit_Mouse_Move()
    local x = love.mouse.getX()
    local y = love.mouse.getY()
    if x >= 600 and x <= 700 and y >= 400 and y <= 450 then
        if love.mouse.isDown(1) then
            Button_Sure_color = Button_pressed_color
            love.window.close()
        else
            Button_Sure_color = Button_inside_color
        end
    else
        Button_Sure_color = Button_outside_color
    end
    if x >= 800 and x <= 900 and y >= 400 and y <= 450 then
        if love.mouse.isDown(1) then
            Button_Cancel_color = Button_pressed_color
            Judge_exit = false
        else
            Button_Cancel_color = Button_inside_color
        end
    else
        Button_Cancel_color = Button_outside_color
    end
end

function Menu_Mouse_Move()
    local x = love.mouse.getX()
    local y = love.mouse.getY()
    if x >= 700 and x <= 800 and y >= 300 and y <= 350 then
        if love.mouse.isDown(1) then
            Button_Red_color = Button_pressed_color
            Rect_color = Color.red
        else
            Button_Red_color = Button_inside_color
        end
    else
        Button_Red_color = Button_outside_color
    end
    if x >= 700 and x <= 800 and y >= 400 and y <= 450 then
        if love.mouse.isDown(1) then
            Button_Blue_color = Button_pressed_color
            Rect_color = Color.blue
        else
            Button_Blue_color = Button_inside_color
        end
    else
        Button_Blue_color = Button_outside_color
    end
    if x >= 700 and x <= 800 and y >= 500 and y <= 550 then
        if love.mouse.isDown(1) then
            Button_Close_color = Button_pressed_color
            Judge_menu = false
        else
            Button_Close_color = Button_inside_color
        end
    else
        Button_Close_color = Button_outside_color
    end
end

function love.load()
    Border = {x = 0, y = 0, w = 1500, h = 800}
    Border_color = Color.Wheat
    Rect = {x = 100, y = 100, w = 1000, h = 600}
    Rect_color = Color.red
    Button_pressed_color = Color.White
    Button_inside_color = Color.Chocolate
    Button_outside_color = Color.SpringGreen
    --for main
    Circle = {x = 600, y = 400, r = 20, seg = 3600}
    Circle_color = Color.Yellow
    Button_menu = {x = 1200, y = 100, w = 200, h = 200}
    Button_exit = {x = 1200, y = 500, w = 200, h = 200}
    Button_exit_color = Button_outside_color
    Button_menu_color = Button_outside_color
    --for exit
    Exit_rect = {x = 500, y = 300, w = 500, h = 200}
    Exit_color = Color.CadetBlue
    Button_Sure = {x = 600, y = 400, w = 100, h = 50}
    Button_Cancel = {x = 800, y = 400, w = 100, h = 50}
    Button_Cancel_color = Button_outside_color
    Button_Sure_color = Button_outside_color
    --for menu
    Menu_rect = {x = 600, y = 200, w = 300, h = 400}
    Menu_color = Color.CadetBlue
    Button_Red = {x = 700, y = 300, w = 100, h = 50}
    Button_Blue = {x = 700, y = 400, w = 100, h = 50}
    Button_Close = {x = 700, y = 500, w = 100, h = 50}
    Button_Red_color = Button_outside_color
    Button_Blue_color = Button_outside_color
    Button_Close_color = Button_outside_color
end

function love.update(dt)
    if Judge_exit == true then
        Exit_Mouse_Move()
    elseif Judge_menu == true then
        Menu_Mouse_Move()
    else
        Circle_Move()
        Main_Mouse_Move()
    end
end

-- 绘制有颜色的矩形
function love.draw()
    if Judge_exit == true then
        Draw_Border()
        Draw_Rect()
        Draw_Exit()
    elseif Judge_menu == true then
        Draw_Border()
        Draw_Rect()
        Draw_Menu()
    else
        Draw_Border()
        Draw_Rect()
        Draw_Main()
    end
end
